package cn.demoxy.controller;
import cn.demoxy.annotation.Log;
import cn.demoxy.enums.BusinessTypeEnum;
import cn.demoxy.result.R;
import cn.demoxy.service.IDemoDataConfService;
import cn.demoxy.model.dto.DemoDataConfDTO;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;

import cn.demoxy.model.entity.DemoDataConf;

/**
* 数据源表控制层
* @author demo
* @date 2022-05-24
*/
@Api(tags =" 数据源表接口信息 ")
@AllArgsConstructor
@RestController
@RequestMapping("/admin/demo-data-conf")
@CrossOrigin
public class DemoDataConfController {

    private IDemoDataConfService demoDataConfService;

    /**
    * 分页查询所有数据源
    * @params
    * @return
    */
    @ApiOperation(value = "分页查询所有数据源")
    @PostMapping("/page")
    @RequiresPermissions("demo-data-conf:page")
    public R list(@RequestBody DemoDataConfDTO dataConfDTO) {
    return R.ok(this.demoDataConfService.findAllDataSource(dataConfDTO));
    }



    /**
    * 通过id查询
    * @params id
    * @return
    */
    @ApiOperation(value = "通过id查询")
    @GetMapping("/get")
    @RequiresPermissions("demo-data-conf:get")
    public R get(String id) {
    return R.ok(this.demoDataConfService.getById(id));
    }

    /**
    * 添加数据源
    * @params entity
    * @return
    */
    @ApiOperation(value = "添加数据源")
    @PostMapping("/save")
    @Log(title = "数据源管理数据源新增",businessType = BusinessTypeEnum.INSERT)
    @RequiresPermissions("demo-data-conf:save")
    public R save(@RequestBody  DemoDataConf entity) {
    return R.ok(this.demoDataConfService.save(entity));
    }

    /**
    * 更新数据源
    * @params entity
    * @return
    */
    @ApiOperation(value = "更新数据源")
    @PostMapping("/update")
    @Log(title = "数据源管理数据源信息修改",businessType = BusinessTypeEnum.UPDATE)
    @RequiresPermissions("demo-data-conf:update")
    public R update(@RequestBody  DemoDataConf entity) {
    return R.ok(this.demoDataConfService.updateById(entity));
    }

    /**
    * 通过id删除
    * @params id
    * @return
    */
    @ApiOperation(value = "通过id删除")
    @PostMapping("/delete/{id}")
    @Log(title = "数据源管理数据源删除",businessType = BusinessTypeEnum.DELETE)
    @RequiresPermissions("demo-data-conf:delete")
    public R delete(@PathVariable("id") String id) {
    return R.ok(this.demoDataConfService.removeById(id));
    }
    }
